home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / hardware / joysdk11 / sample.lst < prev    next >
File List  |  1992-02-18  |  13KB  |  294 lines

  1.  
  2.  
  3.                                                                                                                             PAGE   1
  4.                                                                                                                             02-18-92
  5.                                                                                                                             09:49:49
  6.  
  7.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  8.  
  9.       1  /*
  10.       2  Sample C code for reading joystick axis
  11.       3  
  12.       4  Joysticks & gamecards vary in their physical characteristics from one to
  13.       5  another.  For this reason the high state duration of joysticks in their extreme
  14.       6  positions must be predetermined for each joystick & gamecard combinations.
  15.       7  The following program will prompt the user to move the joystick to all its
  16.       8  extreme positions at startup time.  Axis high state duration will be recorded
  17.       9  at these positions for computing joystick position at a later time in the
  18.      10  programs.
  19.      11  */
  20.      12  
  21.      13  #include <conio.h>
  22.      14  #include <stdio.h>
  23.      15  
  24.      16  /*
  25.      17  Declare external functions
  26.      18  */
  27.      19  extern void get_loop_count (void);  /* Assembly language module initialization function*/
  28.      20  extern short read_axis (short);  /* Return axis position count function */
  29.      21  
  30.      22  /*
  31.      23  Declare local functions
  32.      24  */
  33.      25  short compute_axis (short, short, short);  /* Compute axis coordinate */
  34.      26  void display_coordinate (void);  /* Display joystick coordinate */
  35.      27  
  36.      28  /*
  37.      29  Declare variable
  38.      30  */
  39.      31  short stick_a_min_x;  /* Minimum high state duration for X axis of joystick A */
  40.      32  short stick_a_max_x;  /* Maximun high state duration for X axis of joystick A */
  41.      33  short stick_a_range_x;    /* Joystick A - X axis travel range */
  42.      34  short stick_a_min_y;  /* Minimum high state duration for Y axis of joystick A */
  43.      35  short stick_a_max_y;  /* Maximum high state duration for Y axis of joystick A */
  44.      36  short stick_a_range_y;    /* Joystick A - Y axis travel range */
  45.      37  short stick_b_min_x;  /* Minimum high state duration for X axis of joystick B */
  46.      38  short stick_b_max_x;  /* Maximun high state duration for X axis of joystick B */
  47.      39  short stick_b_range_x;    /* Joystick B - X axis travel range */
  48.      40  short stick_b_min_y;  /* Minimum high state duration for Y axis of joystick B */
  49.      41  short stick_b_max_y;  /* Maximum high state duration for Y axis of joystick B */
  50.      42  short stick_b_range_y;    /* Joystick B - Y axis travel range */
  51.      43  
  52.      44  main ()
  53.      45  {
  54.      46      /* Initialize assembly language module by calling get_loop_count */
  55.      47      get_loop_count ();
  56.      48  
  57.      49      /* Joystick A */
  58.      50      printf ("Push spacebar when joystick A is farthest to left\n");
  59.      51      /* Wait for spacebar pressed */
  60.      52      while (getch () != 0x20)
  61.      53          ;
  62.      54      /* Spacebar pressed, read joystick A - X axis */
  63.      55      stick_a_min_x = read_axis (0);
  64.      56  
  65.  
  66.  
  67.                                                                                                                             PAGE   2
  68.                                                                                                                             02-18-92
  69.                                                                                                                             09:49:49
  70.  
  71.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  72.  
  73.      57      printf ("Push spacebar when joystick A is farthest to right\n");
  74.      58      /* Wait for spacebar pressed */
  75.      59      while (getch () != 0x20)
  76.      60          ;
  77.      61      /* Spacebar pressed, read joystick A - X axis */
  78.      62      stick_a_max_x = read_axis (0);
  79.      63  
  80.      64      /* Compute joystick A - X axis travel range */
  81.      65      stick_a_range_x = stick_a_max_x - stick_a_min_x;
  82.      66  
  83.      67  
  84.      68      printf ("Push spacebar when joystick A is farthest to top\n");
  85.      69      /* Wait for spacebar pressed */
  86.      70      while (getch () != 0x20)
  87.      71          ;
  88.      72      /* Spacebar pressed, read joystick A - Y axis */
  89.      73      stick_a_min_y = read_axis (1);
  90.      74  
  91.      75      printf ("Push spacebar when joystick A is farthest to bottom\n");
  92.      76      /* Wait for spacebar pressed */
  93.      77      while (getch () != 0x20)
  94.      78          ;
  95.      79      /* Spacebar pressed, read joystick A - Y axis */
  96.      80      stick_a_max_y = read_axis (1);
  97.      81  
  98.      82      /* Compute joystick A - Y axis travel range */
  99.      83      stick_a_range_y = stick_a_max_y - stick_a_min_y;
  100.      84  
  101.      85  
  102.      86  
  103.      87      /* Joystick B */
  104.      88      printf ("Push spacebar when joystick B is farthest to left\n");
  105.      89      /* Wait for spacebar pressed */
  106.      90      while (getch () != 0x20)
  107.      91          ;
  108.      92      /* Spacebar pressed, read joystick B - X axis */
  109.      93      stick_b_min_x = read_axis (2);
  110.      94  
  111.      95      printf ("Push spacebar when joystick B is farthest to right\n");
  112.      96      /* Wait for spacebar pressed */
  113.      97      while (getch () != 0x20)
  114.      98          ;
  115.      99      /* Spacebar pressed, read joystick B - X axis */
  116.     100      stick_b_max_x = read_axis (2);
  117.     101  
  118.     102      /* Compute joystick B - X axis travel range */
  119.     103      stick_b_range_x = stick_b_max_x - stick_b_min_x;
  120.     104  
  121.     105  
  122.     106      printf ("Push spacebar when joystick B is farthest to top\n");
  123.     107      /* Wait for spacebar pressed */
  124.     108      while (getch () != 0x20)
  125.     109          ;
  126.     110      /* Spacebar pressed, read joystick B - Y axis */
  127.     111      stick_b_min_y = read_axis (3);
  128.     112  
  129.  
  130.  
  131.                                                                                                                             PAGE   3
  132.                                                                                                                             02-18-92
  133.                                                                                                                             09:49:49
  134.  
  135.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  136.  
  137.     113      printf ("Push spacebar when joystick B is farthest to bottom\n");
  138.     114      /* Wait for spacebar pressed */
  139.     115      while (getch () != 0x20)
  140.     116          ;
  141.     117      /* Spacebar pressed, read joystick B - Y axis */
  142.     118      stick_b_max_y = read_axis (3);
  143.     119  
  144.     120      /* Compute joystick B - Y axis travel range */
  145.     121      stick_b_range_y = stick_b_max_y - stick_b_min_y;
  146.     122  
  147.     123  
  148.     124  
  149.     125      /* Display joystick coordinate */
  150.     126      while (!kbhit ())
  151.     127            display_coordinate ();
  152.     128      /* Flush keyboard buffer before quitting */
  153.     129      if (getch () == 0)
  154.     130          getch ();
  155.     131  }
  156.     132  
  157.     133  
  158.     134  /*
  159.     135  Display all 4 joystick coordinates from a range of 0 to 100
  160.     136  */
  161.     137  
  162.     138  void display_coordinate ()
  163.     139  {
  164.     140      short stick_a_x, stick_a_y, stick_b_x, stick_b_y;
  165.     141  
  166.     142      stick_a_x = read_axis (0);
  167.     143      if (stick_a_x < stick_a_min_x)
  168.     144          stick_a_x = stick_a_min_x;
  169.     145      else
  170.     146          if (stick_a_x > stick_a_max_x)
  171.     147              stick_a_x = stick_a_max_x;
  172.     148      if (stick_a_range_x == 0)
  173.     149          printf ("         0");
  174.     150      else
  175.     151          printf ("%10d", compute_axis (stick_a_x, stick_a_min_x, stick_a_range_x));
  176.     152  
  177.     153      stick_a_y = read_axis (1);
  178.     154      if (stick_a_y < stick_a_min_y)
  179.     155          stick_a_y = stick_a_min_y;
  180.     156      else
  181.     157          if (stick_a_y > stick_a_max_y)
  182.     158              stick_a_y = stick_a_max_y;
  183.     159      if (stick_a_range_y == 0)
  184.     160          printf ("         0");
  185.     161      else
  186.     162          printf ("%10d", compute_axis (stick_a_y, stick_a_min_y, stick_a_range_y));
  187.     163  
  188.     164  
  189.     165      stick_b_x = read_axis (2);
  190.     166      if (stick_b_x < stick_b_min_x)
  191.     167          stick_b_x = stick_b_min_x;
  192.     168      else
  193.  
  194.  
  195.                                                                                                                             PAGE   4
  196.                                                                                                                             02-18-92
  197.                                                                                                                             09:49:49
  198.  
  199.  Line#  Source Line                                                                                Microsoft C Compiler Version 5.10
  200.  
  201.     169          if (stick_b_x > stick_b_max_x)
  202.     170              stick_b_x = stick_b_max_x;
  203.     171      if (stick_b_range_x == 0)
  204.     172          printf ("         0");
  205.     173      else
  206.     174          printf ("%10d", compute_axis (stick_b_x, stick_b_min_x, stick_b_range_x));
  207.     175  
  208.     176      stick_b_y = read_axis (3);
  209.     177      if (stick_b_y < stick_b_min_y)
  210.     178          stick_b_y = stick_b_min_y;
  211.     179      else
  212.     180          if (stick_b_y > stick_b_max_y)
  213.     181              stick_b_y = stick_b_max_y;
  214.     182      if (stick_b_range_y == 0)
  215.     183          printf ("         0");
  216.     184      else
  217.     185          printf ("%10d\n", compute_axis (stick_b_y, stick_b_min_y, stick_b_range_y));
  218.     186  }
  219.  
  220.  
  221. display_coordinate  Local Symbols
  222.  
  223. Name                      Class   Type              Size   Offset  Register
  224.  
  225. stick_b_y . . . . . . . . auto                             -0008 
  226. stick_a_y . . . . . . . . auto                             -0006 
  227. stick_b_x . . . . . . . . auto                             -0004 
  228. stick_a_x . . . . . . . . auto                             -0002 
  229.  
  230.     187  
  231.     188  
  232.     189  /*
  233.     190  Compute axis coordinate from a range of 0 to 100
  234.     191  */
  235.     192  short compute_axis (axis, min, range)
  236.     193  short axis, min, range;
  237.     194  {
  238.     195      return (((long) 100 * (long) (axis - min)) / (long) range);
  239.     196  }
  240.  
  241.  
  242. compute_axis  Local Symbols
  243.  
  244. Name                      Class   Type              Size   Offset  Register
  245.  
  246. axis. . . . . . . . . . . param                             0004
  247. min . . . . . . . . . . . param                             0006
  248. range . . . . . . . . . . param                             0008
  249.  
  250.  
  251. Global Symbols
  252.  
  253. Name                      Class   Type              Size   Offset  
  254.  
  255. compute_axis. . . . . . . global  near function      ***    02a3
  256. display_coordinate. . . . global  near function      ***    0147
  257.  
  258.  
  259.                                                                                                                             PAGE   5
  260.                                                                                                                             02-18-92
  261.                                                                                                                             09:49:49
  262.  
  263.                                                                                                    Microsoft C Compiler Version 5.10
  264.  
  265.  
  266. Global Symbols
  267.  
  268. Name                      Class   Type              Size   Offset  
  269.  
  270. get_loop_count. . . . . . extern  near function      ***     ***
  271. getch . . . . . . . . . . extern  near function      ***     ***
  272. kbhit . . . . . . . . . . extern  near function      ***     ***
  273. main. . . . . . . . . . . global  near function      ***    0000
  274. printf. . . . . . . . . . extern  near function      ***     ***
  275. read_axis . . . . . . . . extern  near function      ***     ***
  276. stick_a_max_x . . . . . . common  int                  2     ***
  277. stick_a_max_y . . . . . . common  int                  2     ***
  278. stick_a_min_x . . . . . . common  int                  2     ***
  279. stick_a_min_y . . . . . . common  int                  2     ***
  280. stick_a_range_x . . . . . common  int                  2     ***
  281. stick_a_range_y . . . . . common  int                  2     ***
  282. stick_b_max_x . . . . . . common  int                  2     ***
  283. stick_b_max_y . . . . . . common  int                  2     ***
  284. stick_b_min_x . . . . . . common  int                  2     ***
  285. stick_b_min_y . . . . . . common  int                  2     ***
  286. stick_b_range_x . . . . . common  int                  2     ***
  287. stick_b_range_y . . . . . common  int                  2     ***
  288.  
  289. Code size = 02ce (718)
  290. Data size = 01dd (477)
  291. Bss size  = 0000 (0)
  292.  
  293. No errors detected
  294.